package 代码记录.Bit48天集训;

import java.util.*;

/**1.求和(回溯-组合)
 * 2.电话号码(不是回溯)
 * @author zx
 * @create 2022-07-03 21:05
 */
public class day_43 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            List<List<Integer>> res = combine(n, m);
            for(List c : res){
                for(int i = 0;i < c.size();i++){
                    System.out.print(c.get(i) + " ");
                }
                System.out.println();
            }
        }
    }
    private static List<List<Integer>> res = new ArrayList<>();
    private static LinkedList<Integer> list = new LinkedList<>();
    private static List<List<Integer>> combine(int n,int m){
        dfs(n,m,1,0);
        return res;
    }
    private static void dfs(int n,int m,int startIndex,int sum){
        if(sum == m){
            res.add(new ArrayList<>(list));
            return;
        }
        for(int i = startIndex;i <= n;i++){
            sum += i;
            list.add(i);
            dfs(n,m,i + 1,sum);
            list.removeLast();
            sum -= i;
        }
    }


    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] map = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "22233344455566677778889999"};
        while (sc.hasNext()) {
            int n = sc.nextInt();
            //用set保存结果,去重
            Set<String> set = new TreeSet<>();
            for (int i = 0; i < n; i ++ ) {
                StringBuilder sb = new StringBuilder();
                char[] arr = sc.next().replace("-", "").toCharArray();
                for (int j = 0; j < arr.length; j ++ ) {
                    if(j == 3) {
                        sb.append("-");
                    }
                    if(arr[j] >= 'A' && arr[j] <= 'Z') {
                        sb.append(map[1].charAt(map[0].indexOf(arr[j])));
                    }else {
                        sb.append(arr[j]);
                    }
                }
                set.add(sb.toString());
            }
            for (String res : set){
                System.out.println(res);
            }
            System.out.println();
        }
    }
}
